package com.settlement.system.service.impl;

import com.settlement.system.mapper.BaseMapper;
import com.settlement.system.mapper.TblRrRecordProjectMainMapper;
import com.settlement.system.common.enums.BillTypeEnum;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblRrRecordProjectMain;
import com.settlement.system.model.entity.common.TblRrVoucherType;
import com.settlement.system.service.ITblRrRecordProjectMainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 收退款-记账项目主表 服务实现类
 *
 * @author Ximi
 * @since 2020-07-14
 */
@Service
@Slf4j
public class TblRrRecordProjectMainServiceImpl extends BaseServiceImpl implements ITblRrRecordProjectMainService {

    @Resource
    private TblRrRecordProjectMainMapper tblRrRecordProjectMainMapper;

    @Override
    public BaseMapper init() {
        return tblRrRecordProjectMainMapper;
    }

    @Override
    public List<TblRrRecordProjectMain> getByRecordAccountProject(String recordAccountProject) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getByRecordAccountProject(recordAccountProject);
        } catch (Exception ex) {
            log.error("Get TblRrRecordProjectMain By recordAccountProject Happen Exception:",ex);
            throw new ServiceException("Get TblRrRecordProjectMain By recordAccountProject Happen Exception:",ex);
        }
    }

    @Override
    public String getByChannelNoAndBillTypeAndOriginBillProject(String channelNo,String billType,String originBillProject) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getByChannelNoAndBillTypeAndOriginBillProject(channelNo,billType,originBillProject);
        } catch (Exception ex) {
            log.error("Get TblRrRecordProjectMain By recordAccountProject Happen Exception:",ex);
            throw new ServiceException("Get TblRrRecordProjectMain By recordAccountProject Happen Exception:",ex);
        }
    }

    @Override
    public TblRrRecordProjectMain getByChannelNoAndBillTypeAndNotBillCategory(String channelNo,String billType,String notBillCategory) throws ServiceException {
        return getByChannelNoAndBillTypeAndNotBillCategory(channelNo,billType,notBillCategory,null);
    }

    @Override
    public TblRrRecordProjectMain getByChannelNoAndBillTypeAndNotBillCategory(String channelNo,
                                                                              String billType,
                                                                              String notBillCategory,
                                                                              String notId) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getByChannelNoAndBillTypeAndNotBillCategory(channelNo,billType,notBillCategory,notId);
        } catch (Exception ex) {
            log.error("getByChannelNoAndBillType Exception:",ex);
            throw new ServiceException("getByChannelNoAndBillType Exception:",ex);
        }
    }

    /**
     * 根据记账项目,获取不重复的凭证类型
     *
     * @param recordAccountProject 记账项目
     * @param channelNo 渠道编码
     * @param billType 账单类型（仅渠道为优购时加入判断条件）
     * @throws ServiceException
     */
    @Override
    public List<TblRrRecordProjectMain> getUnrepeatableVoucherTypes(String recordAccountProject,String channelNo,String billType) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getUnrepeatableVoucherTypes(recordAccountProject,channelNo,BillTypeEnum.convertToName(billType));
        } catch (Exception ex){
            throw new ServiceException("根据记账项目,获取不重复的凭证类型异常",ex);
        }
    }

    /**
     * 根据记账项目,获取是否参与记账
     *
     * @param recordAccountProject 记账项目
     * @param channelNo 渠道编码
     * @param billType 账单类型
     * @return
     */
    @Override
    public String getIsJoinRecordAccount(String recordAccountProject,String channelNo,String billType) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getIsJoinRecordAccount(recordAccountProject,channelNo,billType);
        } catch (Exception ex){
            throw new ServiceException("根据记账项目,获取是否参与记账异常",ex);
        }
    }



    @Override
    public String getChargeProjectByRecordAccountProject(String recordAccountProject,String channelNo) throws ServiceException {
        try {
            return tblRrRecordProjectMainMapper.getChargeProjectByRecordAccountProject(recordAccountProject,channelNo);
        } catch (Exception ex){
            log.error("记账项目:{},渠道编码:{}，获取不重复的收费项目异常",recordAccountProject,channelNo);
            throw new ServiceException("根据记账项目,获取不重复的收费项目异常",ex);
        }
    }


    @Override
    public List<TblRrRecordProjectMain> selectByParams(TblRrRecordProjectMain tblRrRecordProjectMain) throws ServiceException{
        try {
            return tblRrRecordProjectMainMapper.selectByParams(tblRrRecordProjectMain);
        } catch (Exception ex){
            log.error("selectByParams by tblRrRecordProjectMain happen exception",ex);
            throw new ServiceException("selectByParams by tblRrRecordProjectMain happen exception",ex);
        }
    }
}

